package cn.oowoo.jsr303.controller;


import cn.oowoo.jsr303.common.dto.User;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/jackSon")
@RestController
public class JackSonTestController {

   /* //========================ObjectMapper 测试 START====================
    *//**
     * @Author: BinZhang
     * @Date: 2019/4/20 23:54
     * @Description:测试自定ObjectMapper序列化，修改默认的jackSon序列化
     *
     *//*
    @RequestMapping("/dateTimeTest")
    public Map dateTimeTest(){
        Map map = new HashMap();
        map.put("dateTime",new Date());
        return map;
    }
    //========================ObjectMapper 测试 END=========================


    //==============@JsonIgnorePropertie、@JsonProperty、@JsonIgnore、@JsonFormat、 测试 START==========
    *//**
     * @Author: BinZhang
     * @Date: 2019/4/21 0:48
     * @Description:jackSon序列化测试
     *
     *//*
    @RequestMapping("/jackSonSer")
    public Dept jackSonSer(){
        Dept dept = new Dept();
        //@JsonProperty注解测试
        dept.setId(1);

        //@JsonFormat注解测试
        dept.setCreateTime(new Date());
        //特殊字段测试
        dept.setDName("开发部");
        //正常字段测试
        dept.setDeptDesc("java开发部门");

        //@JsonInclude注解测试
        dept.setEmployee1(null);
        dept.setEmployee2(null);
        dept.setJob1(new Job());
        dept.setJob2(null);

        //@JsonIgnoreType测试
        dept.setCompany(new Company());
        //@JsonUnwrapped 测试
        dept.setCloseTest(new CloseTest());

        return dept;
    }

    public static void main(String[] args) throws JsonProcessingException {
        Dept dept = new JackSonTestController().jackSonSer();
        System.out.println(new ObjectMapper().writeValueAsString(dept));
    }*/
    //================@JsonIgnorePropertie、@JsonProperty、@JsonIgnore、@JsonFormat、 测试 END==============

//=========================@JsonView 测试 START===========================================================
    /**
     * @Author: BinZhang
     * @Date: 2019/4/21 0:54
     * @Description:@JsonView注解测试
     *
     */
    @JsonView(User.NormalView.class)
    @RequestMapping("/jsonView1")
    public Object jsonView1(){
        User user = new User();
        user.setId(1);
        user.setUserName("泡泡");
        user.setPassword("123456");
        return user;
    }
    /**
     * @Author: BinZhang
     * @Date: 2019/4/21 0:54
     * @Description:@JsonView注解测试
     *
     */
    @JsonView(User.PasswordView.class)
    @RequestMapping("/jsonView2")
    public Object jsonView2(){
        User user = new User();
        user.setId(1);
        user.setUserName("泡泡");
        user.setPassword("123456");
        return user;
    }


//=========================@JsonView 测试 END===========================================================


}
